<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
  * 发送模板短信
  * @param to 手机号码集合,用英文逗号分开
  * @param datas 内容数据 格式为数组 例如：array('Marry','Alon')，如不需替换请填 null
  * @param $tempId 模板Id
  */       
function sendTemplateSMS($to,$datas,$tempId)
{
     // 初始化REST SDK
     global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
     $rest = new app\index\validate\REST('app.cloopen.com','8883','2013-12-26');
     $rest->setAccount('8aaf0708588b1d2301589a4ca8640aa1','78b962e131e7429f96e15be7ff10c138');
     $rest->setAppId('8aaf0708588b1d2301589a4ca8ab0aa5');
    
     // 发送模板短信
     $result = $rest->sendTemplateSMS($to,$datas,$tempId);
     if($result == NULL ) {
         $rec['status'] = 1;
         $rec['mess'] = "result error!";
         return $rec;
     }
     if($result->statusCode!=0) {
        $rec['status'] = 2;
        $rec['mess'] = '发送失败';
        return $rec;
         //TODO 添加错误处理逻辑
     }else{
         // 获取返回信息
         $rec['status'] = 0;
         $rec['mess'] = '发送成功';
         //TODO 添加成功处理逻辑
         return $rec;
     }
}

//Demo调用,参数填入正确后，放开注释可以调用 
//sendTemplateSMS("手机号码","内容数据","模板Id");